package com.qianfeng.controller;

import com.qianfeng.dto.R;
import com.qianfeng.dto.userDto;
import com.qianfeng.log.annotations.LogAnnotation;
import com.qianfeng.pojo.SysUserInfo;
import com.qianfeng.service.UserService;
import com.qianfeng.valigroup.Insert;
import com.qianfeng.valigroup.Select;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;

/*
 *@Description:
 *@author:刘哥
 *@Date:86180 2022/9/5 11:09
 */
@RestController
@RequestMapping("/users")
@Api(tags = "用户管理模块")
public class UserController {
    private UserService userService;
    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    @PostMapping("/user")
    @ApiOperation("用户注册")
//    @LogAnnotation(title = "注册用户",business_type = 1)
    public R register(@Validated(Insert.class) @RequestBody userDto userDto){
        System.out.println("userDto = " + userDto);
        userService.addUser(userDto);
        return R.OK(userDto);
    }
//    @GetMapping("/login")
//    @ApiOperation("用户登录")
////    @LogAnnotation(title = "登录",business_type = 0)
////   @Validated(Select.class) 指明该方法的组名,和给校验属性的注解指明位置
//    public R login(@Validated(Select.class) @RequestBody userDto userDto, HttpSession session){
//        System.out.println("userDto = " + userDto);
//        SysUserInfo sysUserInfo =userService.login(userDto.getUsername(),userDto.getPassword());
//        session.setAttribute("user",sysUserInfo);
//        return R.OK();
//    }
}
